package com.ruoyi.system.controller;

import com.ruoyi.system.domain.ChatRole;
import com.ruoyi.system.service.IChatRoleService;
import com.unfbx.chatgpt.OpenAiStreamClient;
import com.unfbx.chatgpt.entity.chat.ChatCompletion;
import com.unfbx.chatgpt.entity.chat.Message;
import com.unfbx.chatgpt.sse.ConsoleEventSourceListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.concurrent.CountDownLatch;

@RestController
public class ChatGptController {

    @Autowired
    IChatRoleService chatRoleService;


    @PostMapping("/startChat")
    public String startChat(String content,Long roleId){
//        ChatRole chatRole = chatRoleService.selectChatRoleById(roleId);
//        String role = chatRole.getRole();
//        String describeText = chatRole.getDescribeText();
//
//        OpenAiStreamClient client = OpenAiStreamClient.builder()
//                .apiKey(Arrays.asList("sk-********","sk-********"))
//                //自定义key的获取策略：默认KeyRandomStrategy
//                //.keyStrategy(new KeyRandomStrategy())
//                //自己做了代理就传代理地址，没有可不不传
////                .apiHost("https://自己代理的服务器地址/")
//                .build();
//        //聊天模型：gpt-3.5
//        ConsoleEventSourceListener eventSourceListener = new ConsoleEventSourceListener();
//        Message message = Message.builder().role(role).content(describeText+content).build();
//        ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build();
//        client.streamChatCompletion(chatCompletion, eventSourceListener);
//        CountDownLatch countDownLatch = new CountDownLatch(1);
//        try {
//            countDownLatch.await();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        // TODO: 2024/4/28  待调试取值返回
        return null;
    }



}
